package Game;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.HashMap;
import javax.imageio.ImageIO;


public class ImageLoader {
	private static ImageLoader single=new ImageLoader();
	public static ImageLoader getImg(){
		return single;
	}
	private HashMap<String,Image> Images=new HashMap<String,Image>();
	
	public Image getImage(String ref){
		if (Images.get(ref) !=null){
			return (Image) Images.get(ref);
		}
		BufferedImage sourceImage = null;
		try{
			sourceImage = ImageIO.read(new File(ref));
		}
		catch(IOException e){
			System.out.println("unable to load "+ref);
		}
		GraphicsConfiguration gconfig= GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
		Image img =gconfig.createCompatibleImage(sourceImage.getWidth(),sourceImage.getHeight(),Transparency.BITMASK);
		img.getGraphics().drawImage(sourceImage,0,0,null);
		return img;
	}
}
